package eraikikon;

import java.awt.BorderLayout;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.Dimension;
import java.awt.Point;

public class TxartelaGaitu extends JFrame {
	
	private TxartelaGaitu tg;
	
	private JPanel jContentPane = null;

	private static final long serialVersionUID = 1L;
	
	private Txartela tx = null;
	
	/**
	 * This is the default constructor
	 */
	public TxartelaGaitu() {
		super();
		tg = this;
		initialize();
		Box box = Box.createHorizontalBox();
		Box box1 = Box.createVerticalBox();
		Box box2 = Box.createVerticalBox();
		JLabel jLabel = new JLabel();
		final JTextField jTextField = new JTextField();
		jTextField.setInputVerifier(new KonprobatuOsokoa());
		JButton jButton = new JButton();
		box1.add(jLabel);
		box1.add(jTextField);
		box2.add(jButton);
		box.add(box1);
		box.add(box2);
		jLabel.setText("                 Txartel Kodea sartu:   ");
		jButton.setText("Ados");
		jContentPane.add(box,BorderLayout.NORTH );
		jButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				ErabKud ek = new ErabKud();
				tx = ek.getTxartela(Integer.parseInt(jTextField.getText()));
				if (tx.getId() == null){
					JOptionPane.showMessageDialog(null, "Txartel kodea ez da zuzena, saiatu berriro");
				}
				else{
					
					TxartelarenDatuakAtera txda=new TxartelarenDatuakAtera(tx);
					txda.setVisible(true);
					tg.setVisible(false);
					
				}
	
			}
		});
	}
	public Txartela txartelaBidali (){
		return tx;
	}
	

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(299, 101);
		this.setLocation(new Point(400, 200));
		this.setContentPane(getJContentPane());
		this.setTitle("Txartel kodearen kontrola");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
		}
		return jContentPane;
	}
	public static void main(String [] args){
		TxartelaGaitu txartelaGaitu=new TxartelaGaitu();
		txartelaGaitu.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		txartelaGaitu.setVisible(true);
	}
}
  //  @jve:decl-index=0:visual-constraint="10,10"
